<template>
	<el-form :model="formData" ref="formRef" :rules="formRules" label-width="8rem">
		<el-row type="flex" :gutter="10">
			<el-col :span="12">
				<el-form-item label="代金券名称" prop="voucher_name">
					<el-input :disabled="isdisabled" v-model="formData.voucher_name" clearable
						placeholder="请输入代金券名称"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="售价" prop="voucher_money">
					<el-input :disabled="isdisabled" v-model="formData.voucher_money" clearable
						placeholder="请输入售价"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="抵扣金额" prop="usable_money">
					<el-input :disabled="isdisabled" v-model="formData.usable_money" clearable
						placeholder="请输入抵扣金额"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="库存" prop="voucher_num">
					<el-input :disabled="isdisabled" v-model="formData.voucher_num" clearable
						placeholder="请输入库存"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="过期天数" prop="use_day">
					<el-input :disabled="isdisabled" v-model="formData.use_day" clearable
						placeholder="请输入过期天数"></el-input>
				</el-form-item>
			</el-col>
			<!-- 0否 1是 -->
			<el-col :span="12">
				<el-form-item label="周末是否可用" prop="weekend_use">
					<el-radio-group v-model="formData.weekend_use">
						<el-radio :label="0">否</el-radio>
						<el-radio :label="1">是</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col>
			<!-- 0否 1是 -->
			<el-col :span="12">
				<el-form-item label="节假日是否可用" prop="holidays_use">
					<el-radio-group v-model="formData.holidays_use">
						<el-radio :label="0">否</el-radio>
						<el-radio :label="1">是</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="所属商户" prop="store_id">
					<el-select v-model="formData.store_id" placeholder="请选择" :disabled="isdisabled">
						<el-option v-for="(item,index) in statuslist" :key="index" :label="item.merch_name"
							:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-col>
			<!-- 1=上架 0=下架 -->
			<el-col :span="12">
				<el-form-item label="状态" prop="status">
					<el-radio-group v-model="formData.status">
						<el-radio :label="0">下架</el-radio>
						<el-radio :label="1">上架</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="使用须知" prop="ship_note">
					<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入使用须知" v-model="formData.ship_note">
					</el-input>
				</el-form-item>
			</el-col>
		</el-row>
		<el-row type="flex" justify="center">
			<el-button type="primary" :disabled="isdisabled" icon="el-icon-check" @click="onConfirm">确认</el-button>
			<el-button type="default" icon="el-icon-close" @click="onCancel">取消</el-button>
		</el-row>
	</el-form>
</template>

<script>
	import {
		get,
		post,
		del,
		imghttp
	} from '@/assets/js/http'
	export default {

		name: "member-search",
		props: {
			formData: {
				type: Object,
				default: () => {}
			},
			isdisabled: {
				type: Boolean,
				default: false
			}
		},
		components: {
			"el-upload-image": () => import("@/components/el-upload-image.vue"),
		},
		data() {
			return {
				formRules: {
					voucher_name: [{
						required: true,
						message: '请输入',
						trigger: 'change'
					}],
					voucher_money: [{required: true,message: '请输入',trigger: 'change'}],
					usable_money: [{required: true,message: '请输入',trigger: 'change'}],
					use_day: [{required: true,message: '请输入',trigger: 'change'}],
					voucher_num: [{
						required: true,
						message: '请输入',
						trigger: 'change'
					}],
					weekend_use: [{required: true,message: '请选择',trigger: 'change'}],
					holidays_use: [{required: true,message: '请选择',trigger: 'change'}],
					store_id: [{required: true,message: '请选择',trigger: 'change'}],
					status: [{required: true,message: '请选择',trigger: 'change'}],
					ship_note: [{
						required: true,
						message: '请输入',
						trigger: 'change'
					}],
				},
				statuslist: [], //状态 o待打款 1已打款
			};
		},
		mounted() {
			this.getList()
		},
		methods: {
			async getList() {
				this.$loading()
				await get({
					url: '/admin/store.merchant/index',
					params: {
						limit: 999999
					}
				}).then(res => {
					this.statuslist = res.list
					this.$loading().close()
				})
			},
			onConfirm() {
				this.$refs.formRef.validate((valid) => {
					if (valid) {
						// alert('submit!');
						console.log(this.formData)
						this.$emit("search", this.formData);
						this.$parent.$emit("update:visible", false);
						this.$refs.formRef.resetFields()
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			onCancel() {
				this.$parent.$emit("update:visible", false);
				this.$refs.formRef.resetFields();
			}
		}
	};
</script>